Relayout Hard Drive 1

Hard Drive Layout

Like all machines now, the laptop comes with Windows pre-installed and a recovery partition and no CD/DVDs. I have no plns to use Windows at all, so I backed up the whole disk via dd to a file image on a spare USB hard drive. I then installed Ubuntu Budgie 20.10 using full disk encryption and the whole hard drive.

Linux is installed in an encrypted partion which contains two LVMs, one for swap and one for root.

lsblk -o NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT

NAME                          TYPE    SIZE FSTYPE      MOUNTPOIN
nvme0n1                       disk  476.9G             
├─nvme0n1p1                   part    512M vfat        /boot/efi
├─nvme0n1p2                   part    732M ext4        /boot
├─nvme0n1p3                   part     75G crypto_LUKS 
│ └─nvme0n1p3_crypt           crypt   475G LVM2_member 
│   ├─vgubuntu--budgie-swap_1 lvm       1G swap        [SWAP]
│   └─vgubuntu--budgie-root   lvm     474G ext4        /

There are two issues with the above layout. Ubuntu only installs 1GB of swap, which is not enough if S4 Hibernate is required. Also I am not keen on everything being in one large root partition.


Relayout Hard Drive

There are two issues with the above layout. Ubuntu only installs 1GB of swap, which is not enough if S4 Hibernate is required. Also I am not keen on everything being in one large root partition.

The first task is to mount and backup the root filesystem. To do this we use a spare USB drive with atleast 30GB of free space, and boot from an Ubuntu Live USB stick.

Mount the encrypted volume:

root@ubuntu-budgie:~# cryptsetup open /dev/nvme0n1p3 linux
Enter passphrase for /dev/nvme0n1p3: 

Scan for volume groups:

root@ubuntu-budgie:~# vgscan
  Found volume group "vgubuntu-budgie" using metadata type lvm2

root@ubuntu-budgie:~# vgchange -ay
  2 logical volume(s) in volume group "vgubuntu-budgie" now active
 

Scan for volume groups and logical volumes:

root@ubuntu-budgie:~#  lvscan 
  ACTIVE            '/dev/vgubuntu-budgie/swap_1' [980.00 MiB] inherit
  ACTIVE            '/dev/vgubuntu-budgie/root' [473.00 GiB] inherit

Mount the root partition:

root@ubuntu-budgie:~# mkdir /media/root
root@ubuntu-budgie:~# mount /dev/vgubuntu-budgie/root /media/root

Mount a USB drive with atleast 30GB of space:

root@ubuntu-budgie:~# cd /media/data
root@ubuntu-budgie:/media/data# mkdir BACKUP

Backup / to the USB drive:

root@ubuntu-budgie:/media/data# cd BACKUP
root@ubuntu-budgie:/media/data/BACKUP# cp -a /media/root/. .

Unmount the root filesystem:

umount /media/root

The next step is DESCRUCTIVE. It will delete the Linux installation. All data will be LOST. Only do this on a new install, if you know what you are doing, and if you have backed up the data following the steps above!

Delete the logical volumes:

lvremove /dev/vgubuntu-budgie/swap_1
lvremove /dev/vgubuntu-budgie/root

Note at this stage if you only want to increase swap, at the expense of the root volume there is no need to change the disk partition and volume group. You can skip straight to recreating the logical volumes. LINK here STEVE.

Delete the logical volumes:

cryptsetup remove /dev/mapper/linux

Change the size of the /dev/nvme0n1p3 partion using your favourite disk utility tool:

fdisk /dev/nvme0n1

Create smaller partition /dev/nvme0n1p3. I shrunk it to 75GB and created a new 400GB /dev/nvme0n1p4 which will be an encrypted LUKS volume and hold all my data.

NAME                          TYPE    SIZE FSTYPE      MOUNTPOINT
nvme0n1                       disk  476.9G             
├─nvme0n1p1                   part    512M vfat        /boot/efi
├─nvme0n1p2                   part    732M ext4        /boot
├─nvme0n1p3                   part     75G crypto_LUKS 
│ └─nvme0n1p3_crypt           crypt    75G LVM2_member 
│   ├─vgubuntu--budgie-swap_1 lvm       9G swap        [SWAP]
│   └─vgubuntu--budgie-root   lvm      66G ext4        /
└─nvme0n1p4                   part  400.7G crypto_LUKS 
  └─mydata                    crypt 400.7G ext4        /DATA <--New partion to hold data

Create an encrypted volume on the 75GB /dev/nvme0n1p3 partition:

cryptsetup -y -v luksFormat /dev/nvme0n1p3

cryptsetup open /dev/sda3 linux

Create physical and logical volumes:

pvcreate /dev/mapper/linux

vgcreate vgubuntu-budgie /dev/mapper/linux

Create two logical volumes in the 75GB partition. I used 9GB to match the memory, use smaller if you do not need to hubernate.

lvcreate -L 9G vgubuntu-budgie -n swap_1    

lvcreate -l 100%FREE vgubuntu-budgie -n root

Create the filesystems on the two new logical volumes:

mkswap /dev/vgubuntu-budgie/swap_1 

mkfs.ext4 /dev/vgubuntu-budgie/root 

The layout should look something like this now:

lsblk -o NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT,UUID

NAME                  TYPE    SIZE FSTYPE    MOUNTPOINT UUID
nvme0n1               disk  476.9G                      
├─nvme0n1p1           part    512M vfat      /boot/efi  44BA-16B5
├─nvme0n1p2           part    732M ext4      /boot      ad71056c-f2c5-454b-b36a-5ec55f21b226
└─nvme0n1p3           part     75G crypto_LU            b6a7071a-e553-4e95-9544-9dc9ddcfed61
  └─nvme0n1p3_crypt   crypt    75G LVM2_memb            T25pQf-qlNw-pwNV-5dvg-xOTO-KoKG-tW3CjD
    ├─vgubuntu--budgie-swap_1
    │                 lvm       9G swap      [SWAP]     b02b828e-f0bf-4ecb-910a-b88392056049
    └─vgubuntu--budgie-root
                      lvm      66G ext4      /          c525d5a2-023a-42af-98fc-0e24b8de4aa3

Mount the newly created empty root partition:

mount /dev/vgubuntu-budgie/root  /media/root

Copy back the root filesystem from the USB backup created earlier:

cd /media/root
cp -a /media/data/BACKUP/* .

Next we need to adjust the luksUUID of /dev/nvme0n1p3 to match what was in /etc/crypttab:

cat /media/root/etc/crypttab

nvme0n1p3_crypt UUID=6b1a9ade-99a7-4778-baf0-106bd2f21254 none luks,discard

Change the luksUUID of /dev/nvme0n1p3 to match the output above:

cryptsetup luksUUID /dev/nvme0n1p3 --uuid "6b1a9ade-99a7-4778-baf0-106bd2f21254"

Now reboot and the new disk layout should be effective!

lsblk -o NAME,TYPE,SIZE,FSTYPE,MOUNTPOINT

NAME                          TYPE    SIZE FSTYPE      MOUNTPOINT
nvme0n1                       disk  476.9G             
├─nvme0n1p1                   part    512M vfat        /boot/efi
├─nvme0n1p2                   part    732M ext4        /boot
├─nvme0n1p3                   part     75G crypto_LUKS 
│ └─nvme0n1p3_crypt           crypt    75G LVM2_member 
│   ├─vgubuntu--budgie-swap_1 lvm       9G swap        [SWAP]
│   └─vgubuntu--budgie-root   lvm      66G ext4        /
└─nvme0n1p4                   part  400.7G crypto_LUKS 
  └─mydata                    crypt 400.7G ext4        /DATA

We are now good to go.